<?php

namespace App\Http\Controllers;

use App\Http\Controllers\BaseController;
use App\Services\MeetPersonService;
use Illuminate\Http\Request;

class MeetPersonController extends BaseController
{
    public function __construct(MeetPersonService $meetPersonService)
    {
        $this->middleware('check.login')->except('index');

        $this->meetPersonService = $meetPersonService;
    }

    public function index(Request $request)
    {
        $param = $this->validationParameter([
            'page|页码' => 'noRequire|number|default:1',
            'per_page|显示数量' => 'noRequire|number|default:30',
        ]);

        $param['add_uid'] = $request->user('api')->user_id ?? null;

        $data = $this->meetPersonService->getList($param);

        return $this->response->success($data);
    }

    public function show(Request $request)
    {
        $id = $request->input('id');
        $result = $this->meetPersonService->getInfo($id);

        return $this->response->success($result);
    }

    public function store(Request $request)
    {
        $param = $this->validationParameter([
            'name|姓名' => 'require',
            'sex|性别' => 'require',
            'phone|手机' => 'require',
            'paper_type|证件类型' => 'require',
            'paper|证件' => 'require',
        ]);

        $param['add_uid'] = $request->user('api')->user_id ?? null;

        $result = $this->meetPersonService->add($param);

        return $this->response->success($result);
    }

    public function update(Request $request)
    {
        $id = $request->input('id');
        $param = [];
        $result = $this->meetPersonService->update($param, $id);

        return $this->response->success($result);
    }

    public function destroy(Request $request)
    {
        $id = $request->input('id');
        $result = $this->meetPersonService->delete($id);

        return $this->response->success($result);
    }
}
